<% # frozen_string_literal: true %>

<div class="modal-content" id="user_assignments_modal" data-action="modal-close" data-target="<%= public_send("#{assignable.class.name.pluralize.underscore}_path") %>">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="sn-icon sn-icon-close"></i></button>
    <h4 class="modal-title">
      <%= t '.title', resource_name: assignable.name %>
      <%= link_to assignable_path, remote: true, class: 'pull-left mr-2', data: { action: 'swap-remote-container', target: '#user_assignments_modal' } do %>
        <i class="fas fa-arrow-left"></i>
      <% end %>
    </h4>
  </div>
  <%= form_with(url: create_path, method: :post, html: { id: 'new-user-assignment-form', data: { remote: true, object_type: assignable.class.to_s.downcase } }) do |f| %>
    <div class="modal-body">
      <div class="sci-input-container left-icon">
        <%= text_field_tag :search_users, '',
                           placeholder: t('.find_people_html'),
                           class: 'sci-input-field new-assignment-user-search',
                           data: { action: 'filter-list', target: 'new-user-assignment-form' } %>
        <i class="sn-icon sn-icon-search"></i>
      </div>
      <% if assignable.visibility && assignable.visibility == 'hidden' %>
        <%= f.fields_for :users, UserAssignment.new do |user_form| %>
          <%= render 'access_permissions/partials/public_assignment_field', user_form: user_form, assignable: assignable  %>
        <% end %>
      <% end %>
      <% users.each do |user| %>
        <%= f.fields_for :users, UserAssignment.new(user: user) do |user_form| %>
          <%= render 'access_permissions/partials/user_assignment_field', user_form: user_form, assignable: assignable  %>
        <% end %>
      <% end %>
    </div>
    <div class="modal-footer">
      <%= f.submit t('.submit'), class: "btn btn-primary", disabled: true, data: { 'label-default' =>  t('.submit'),  'label-singular' => t('.submit_singular'), 'label-plural' => t('.submit_plural') }%>
    </div>
  <% end %>
</div>
